﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
using CloudTree.Domain;

namespace CloudTree.Infrastructure
{
    public class DepartmentDB : DbContext, IDepartmentDataSource // implements IDepartmentDataSource - controllers do not know about DepartmentDB directly - making it more flexible
    {
        public DepartmentDB()
            : base("DefaultConnection")
        { 

        }

        public DbSet<Employee> Employees { get; set; }//DBSet defiend by Entity framework - type - derives from IQueryable and IEnumerable
        public DbSet<Department> Departments { get; set; }

        void IDepartmentDataSource.Save()
        {
            SaveChanges();//Part of DBContext - goes out through all objects I told it to manage and figuers what to change - generating Insert, Update and Delete statments as needed
        }


        IQueryable<Employee> IDepartmentDataSource.Employees
        {
            get { return Employees; }//DBSet type
        }

        IQueryable<Department> IDepartmentDataSource.Departments
        {
            get { return Departments; }
        }
    }
}